# -*- coding: utf-8 -*-
import mysql.connector
import jsonRW

config = {
    'host': 'sanyajiyu.gotoftp3.com',
    'port': 3306,
    'user': 'sanyajiyu',
    'password': 'bj2kkcbz',
    'database': 'sanyajiyu',
    'charset': 'utf8'
}
'''
config = {
    'host': 'localhost',
    'port': 3306,
    'user': 'root',
    #'password': 'bj2kkcbz',
    'database': 'buxiugang',
    'charset': 'utf8'
}
'''
data = {}
data = jsonRW.load("data.json")

'''
conn = mysql.connector.connect(**config)
cursor = conn.cursor()
cursor.execute("update destoon_member set company='"+ data[0]['company'].encode("utf-8")+"', truename='逗你玩 ', mobile='123123123' where userid=52")
conn.commit()
cursor.close()
conn.close()
'''
conn = mysql.connector.connect(**config)
cursor = conn.cursor()
i = 23

for j in data:
    sql1 = "update destoon_member set "
    sql2 = "update destoon_company set "
    company = ''
    truename = ''
    mobile = ''
    if j.has_key('company'):
        company = "company='"+ j['company'].encode("utf-8") + " ' "
    if j.has_key('truename'):
        truename = "truename='"+ j['truename'].encode("utf-8") + " ', "
    if j.has_key('phone'):
        mobile = "mobile='"+ j['phone'].encode("utf-8") + " ' "
	sql1 = sql1 + company+ ", "+ truename + mobile+ " where userid="+str(i) +";"

	sql2 = sql2 + company +" where userid="+str(i) +";"
	cursor.execute(sql1)
	cursor.execute(sql2)
	i = i+1
conn.commit()
cursor.close()
conn.close()

'''
int convert string : int(string)
string convert string : str(number)
利用 import 文件名来导入 同一文件夹下的文件
    jsonRW.load("data.json") #调用相应的函数

if __name__ = "__main__" :
    作为入口
j.has_key（） #关联数组中是否有相应的key

在if语句内定义的变量的在if语句外是无法使用的，代码块的作用，隐含了{}的存在

'''